/*
 *ScoreKeeper class is in charge of keeping track of:
 *strikes, balls, outs, innings and score, hits and errors during a game.
 */
#ifndef SCOREKEEPER_H
#define SCOREKEEPER_H
#include <QObject>
#include "player.h"
#include "gamestatistic.h"
#include <QVector>
#include <QDate>

class ScoreKeeper
{
public:
    ScoreKeeper(QVector<Player*> home, int hPitcher, QVector<Player*> away, int aPitcher);
    ScoreKeeper(ScoreKeeper* other);
    ~ScoreKeeper();
    int getHomeScore();
    int getAwayScore();
    void addToScore(int runs); //determine who to add runs to by using isBottomHalf();
    int getHomeHits();
    int getAwayHits();
    void incrementHits(); //determine who to add hits to by using isBottomHalf()
    int getHomeErrors();
    int getAwayErrors();
    void addToErrors(int errors); //determine who to add errors to by using isBottomHalf()
    int getStrikes();
    int getBalls();
    int getOuts();
    int getInning();
    bool isBottomHalf();
    void incrementStrikes();
    bool incrementBalls();
    void foulBall();
    bool isGameOver();
    QVector<Player*> getHomeLineup();
    QVector<Player*> getAwayLineup();
    void setHomeLineUp(QVector<Player*> homeLineup);
    void setAwayLineup(QVector<Player*> awayLineup);
    void incrementOuts();
    Player* whosAtBat();
    void incrementLineupPosition();
    Player* whosOnFirst();
    Player* whosOnSecond();
    Player* whosOnThird();
    void homerun();
    void single();
    void hitDouble();
    void triple();
    GameStatistic getCurrentPlayerStats();
    QVector<GameStatistic*> getHomeStats();
    QVector<GameStatistic*> getAwayStats();
    QVector<Player*> homeLineup;
    QVector<Player*> awayLineup;
    void setFirst(Player* p);
    void setSecond(Player* p);
    void setThird(Player* p);
    GameStatistic getPlayerStats(Player* p);
    int getHomeLineupPosition();
    int getAwayLineupPosition();
    int getHomePitcher();
    int getAwayPitcher();
    int getPlayerLineupPosition(Player* p);
    void attributeRun(Player* p);
    void attributeRBI();

signals:
    void gameOver();

private:
    //constant values
    int REGULATION_INNINGS;
    int MAX_NUMBER_OF_STRIKES;
    int MAX_NUMBER_OF_BALLS;
    int MAX_NUMBER_OF_OUTS;

    int homeScore;
    int awayScore;
    int homeHits;
    int awayHits;
    int homeErrors;
    int awayErrors;
    int strikes;
    int balls;
    int outs;
    int inning;
    bool bottomHalfOfInning;//needed to know when to increment inning(inning = 2 halves, away team bats, home team bats) bottom of the inning is when the home team bats.

    int homeLineupPosition;
    int awayLineupPosition;
    Player* atBat;
    Player* first;
    Player* second;
    Player* third;
    QVector<GameStatistic*> homeStats;
    QVector<GameStatistic*> awayStats;
    int homePitcher;
    int awayPitcher;

    void incrementInning();
    void toggleBottomHalf();
    void resetAtBat();
    void resetInning();
    void clearBases();



};

#endif // SCOREKEEPER_H
